home *** CD-ROM | disk | FTP | other *** search
- Path: surfnet.nl!sun4nl!xs4all!falstaff
- From: falstaff@xs4all.nl (Falstaff)
- Newsgroups: comp.lang.c
- Subject: Re: PLEASE Help! :(
- Date: 10 Mar 1996 15:42:40 GMT
- Organization: XS4ALL, networking for the masses
- Message-ID: <4hut9g$p15@news.xs4all.nl>
- References: <4hsqk2$4d7@deadbird.db.erau.edu>
- NNTP-Posting-Host: xs1.xs4all.nl
- X-Newsreader: NN version 6.5.0 #666 (NOV)
-
- kochank@news.db.erau.edu (Konrad Kochan) writes:
-
- >Howdy.. I have a program to write, but I'm clueless... Now I could
- >give you a 100 excuses and blame the instructor (and I should cause
- >all of it would be true.. :)
-
- >Anyways, I'm clueless.. can someone, a good samaritan (or someone just
- >bored..) help me out!
-
- >Here is the program statement..
-
- >Write a C program to sort, using any sorting method, a text file
- >named RECORDS.DAT, of unknown length, of records organized as follows:
-
- >Field 1. Contains an integer.
- >Field 2. Contains a string of exactly 20 characters.
- >Field 3. Contains a float followed by a newline character.
-
- >Example of file organization:
-
- >234 Numa Chaikin 33000.0
- > 75 advertisements 55.55
- >901 Shepard 15255.5
- > 3 Brook 120050.0
- >888 non-descriptive 0.0
-
- >Sorting has to be done lexicographically, that is, by the second field
- >using alphabetical order. This means that:
-
- >1. Upper-case and lower-case letters should be treated identically.
- > For example, the right order for a part of the list above is:
- > 888 non-descriptive 0.0
- > 234 Numa Chaikin 33000.0
-
- >2. The only punctuation sign used in strings is a dash '-', which
- > should be ignored in sorting (but not removed from words).
- >And here is what I got so far.. which DOESN'T work (right or otherwise, I
- >can't even get the program to scan the right fields from the file.. :(
-
- >#include <stdio.h>
- >#include <stdlib.h>
- >#include <string.h>
-
- >/* Global Variable Definition */
-
- >int IntArr[512][5];
- >char WordsArr1[512][10];
- >char WordsArr2[512][10];
- >float FloatArr[512][5];
- >char inbuff[80];
- >int index=0;
-
- >/* Function declaration */
-
- >void Welcome(void);
- >void Goodbye(void);
-
- >main()
- >{
- >/* Next function opens a file, if the file is missing, it prints
- > an error message */
- >
- >int i;
- > FILE * fin, * fout;
- > if (!(fin = fopen("RECORDS.DAT", "r")))
- > {
- > printf("Something is wrong: Probably file missing.\n");
- > exit(1); /* Program exits here if file is missing. */
- > }
- > printf("\nInput File = RECORDS.DAT\n");
- >/* This function prints a Welcome message */
-
- >/* Welcome(); */
-
- >/* This function scans in the array */
-
- > while (fgets(inbuff,80,fin) !=NULL)
- >{
- >sscanf(inbuff,"%d %s %s %4.2f", &IntArr[index],&WordsArr1[index],&WordsArr2[index],&FloatArr[index]);
- >index++;
- >}
-
- >/* Opens the output file */
-
- >if (!(fout = fopen("test", "w")))
- > {
- > printf("Something is wrong: File might be write protected.\n");
- > exit(1); /* Program exits here if file can't be opened. */
- > }
-
- > for (i=0; i<index; i++)
- > fprintf(fout, "%d %s %s %4.2f\n", IntArr[i], WordsArr1[i],WordsArr2[i],
- > FloatArr[i]);
- >
- >/* Prints the sorted array to the screen */
- >
- > for (i=0; i<index; i++)
- > printf("Original array: %d %s %s %4.2f \n", IntArr[i],WordsArr1[i],
- >WordsArr2[i],FloatArr[i]);
- >fclose(fin);
- >fclose(fout);
- >}
- >If you can either give me hints, rewrite the above, or write a totaly
- >new program I would appreciate it.. I know its a lot to ask for (to do some-
- >one elses homework pretty much..) but I'm really clueless..
-
- You must be if you think we're going to solve your homework for you.
- But, I'm feeling helpful today so I'll write your program.
- Here it is:
-
- int main()
- {
- return system("sort -f +2 -3 -o RECORDS.DAT RECORDS.DAT");
- }
-
- Payment before the end of the month by crossed check or postal order
- for US$100 to my home address please.
-
- Frank
- --
- The famous GIICM now on line: http://www.xs4all.nl/~falstaff/GIICM.html
- ------------------------------------------------------------------------
- Frank A. Vorstenbosch +31-(70)-355 5241 falstaff@xs4all.nl
-